<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'/>
    <link href='../packages/core/main.min.css' rel='stylesheet'/>
    <link href='../packages/daygrid/main.min.css' rel='stylesheet'/>
    <link href='../packages/timegrid/main.min.css' rel='stylesheet'/>
    <link href='../packages/list/main.min.css' rel='stylesheet'/>
    <style>
        body {
            margin: 40px 10px;
            padding: 0;
            font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
            font-size: 14px;
        }
        #calendar {
            max-width: 900px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div id='calendar'></div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src='../packages/core/main.min.js'></script>
<script src='../packages/interaction/main.min.js'></script>
<script src='../packages/daygrid/main.min.js'></script>
<script src='../packages/timegrid/main.min.js'></script>
<script src='../packages/list/main.min.js'></script>
<script src="../packages/core/locales/zh-cn.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        var dataList = [],
            calendarEl = document.getElementById('calendar');
        getList().done(function() {
            var calendar = new FullCalendar.Calendar(calendarEl, {
                plugins: [ 'dayGrid', 'timeGrid', 'list', 'interaction' ],
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
                },
                locale: 'zh-cn',
                editable: true,
                eventLimit: true,
                selectable: true,
                selectMirror: false,
                businessHours: true,
                firstDay: 0,
                weekNumbers: true,
                weekNumbersWithinDays: true,
                select: function(arg) {
                    var title = prompt('事件名称：');
                    if (title) {
                        calendar.addEvent({
                            title: title,
                            start: arg.start,
                            end: arg.end,
                            allDay: arg.allDay
                        })
                    }
                    calendar.unselect()
                },
                eventLimitClick: function(info) {
                    console.log(info);
                    // info.jsEvent();
                },
                events: dataList
            });

            calendar.render();
        });

        function getList() {
            return $.getJSON('./json/list.json', function(res) {
                res.forEach(function(item) {
                    dataList.push({
                        title: item.name,
                        start: new Date(item.start),
                        end: new Date(item.end),
                        url: item.url
                    })
                });
            });
        }

    });

</script>
</html>
